package com.joe.demo.netty;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.*;

/**
 * @Description
 * @Author gaojw
 * @Date 2024-08-29
 */
@Slf4j
public class TestJdkFuture {

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        // 1. 线程池
        final ExecutorService executorService = Executors.newFixedThreadPool(2);
        // 2. 提交任务
        final Future<Integer> future = executorService.submit(new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                log.info("执行计算");
                return 50;
            }
        });
        // 3. 主线程通过 future 来获取结果
        log.info("等待结果");
        log.info("结果是：{}", future.get());
    }
}
